
import pandas as pd
import numpy as np
from pyecharts import Bar

# Create your ana here.


class ChipotleNan:

    def __init__(self):

        self.csv_name =r'D:\vritualenv\django_date\data_ana\first\chips.csv'

        self.df = pd.read_csv(self.csv_name, sep='\t')

    # def bar(self, axis0, axis1, name='test', table_name='test1'):
    #
    #     bar = Bar(name)
    #
    #     bar.add("商家A", axis0, axis1, is_label_show=True, is_datazoom_show=True)
    #
    #     return bar

    #生成series

    def series_to_bar(self,series, name='test', table_name='test1'):

        bar = Bar(name)

        axis0=series.index

        axis1=np.round(series.values.ravel(),1)

        bar.add("商家A", axis0, axis1, is_label_show=True, is_datazoom_show=True)

        return bar


    def how_many_are_sold_per_item(self):

        df1 = self.df.groupby('item_name').sum()

        df1.drop('order_id', axis=1,inplace=True)

        return df1

    def bar_how_many_are_sold_per_item(self):

        info=self.how_many_are_sold_per_item()

        bar=self.series_to_bar(info)

        return bar

    #每一种商品的消费额

    def how_much_are_sold_per_item(self):

        ipr=self.df.quantity*(self.df.item_price.str.replace("$","").astype("float64"))

        df1=self.df.copy()

        df1['ipr'] = ipr

        df1_group=df1.groupby("item_name").sum()

        df1_group.drop("order_id",axis=1,inplace=True)

        df1_group.drop("quantity", axis=1, inplace=True)

        return df1_group

    def bar_how_much_are_sold_per_item(self):

        info=self.how_much_are_sold_per_item()

        bar=self.series_to_bar(info)

        return bar
